<?php
function Upload_Resize_new($path,$immagine,$tmp_img){		// function loading image used by gestione_categorie.php
	$error['flag'] = FALSE;
	$error['msg'] = "";
	$uploads = wp_upload_bits($immagine,NULL ,file_get_contents($tmp_img));
	if(!($uploads['error'] == FALSE)){ 
		//print_r($uploads);
		$error['flag'] = TRUE;
		$error['msg'] = "wp_upload_bits error<br>";
		return $error;
	}
	//echo 'file = '.$uploads['file'].'======<br>';
	//echo 'url  = '.$uploads['url']. '======<br>';
	//echo 'dest = '.$path. "lista/lista/".$immagine;
	$moveResult = rename( $uploads['file'] , $path."lista/lista/".$immagine );
	if ($moveResult == FALSE){
		$error['flag'] = TRUE;
		$error['msg'] = "rename file error";
		return $error;
	}	
	$resize = new resize;
	$resize->urlimage = $path."lista/lista/".$immagine;
	$resize->fisso = 0;
	$resize->maxX = 600;
	$resize->maxY = 600;
	$resize->latofisso = "X";
	$resize->folder = $path."lista/lista/thumbnails/";
	$resize->newName = "thumb_".$immagine;
	//
	$size = getimagesize($resize->urlimage);
	//echo '<br>$size[0]*$size[1]*4 = '.$size[0]*$size[1]*4 .'<br>';
	//echo '<br>memory_get_peak_usage()= '.memory_get_peak_usage().'<br>';
	if (($size[0]*$size[1]*4)>80000000){
			//echo "<script>alert('image to big = ".($size[0]*$size[1]*4)>8000000). "!!')</script>";
			$resize->errore[0] = 'image to big = '.($size[0]*$size[1]*4).'>80000000 !!';
		}else{
			$resize->go();
			unset($resize);


		$resize = new resize;
		$resize->urlimage = $path."lista/lista/".$immagine;
		$resize->fisso = 0;
		$resize->maxX = 600;
		$resize->maxY = 600;
		$resize->latofisso = "X";
		$resize->folder = $path."lista/lista/";
		$resize->newName = "grande_".$immagine;
		//$resize->go();
		//@unlink($path."lista/lista/".$immagine);
		$moveResult = rename( $path."lista/lista/".$immagine , $path."lista/lista/grande_".$immagine );
		}	
	//	
	if(count($resize->errore)==0){
		/*
		echo "Nome file originale: ".$resize->originalName."<br>";
		echo "Altezza file originale: ".$resize->originalY."<br>";
		echo "Larghezza file originale: ".$resize->originalX."<br>";
		echo "Nuova Altezza: ".$resize->newY."<br>";
		echo "Nuova Larghezza: ".$resize->newX."<br>";
		*/
	}else{
		$error['flag'] = TRUE;
		$error['msg'] = implode('<br>', $resize->errore);
		return $error;
	}
}
